<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>仪表盘 - 日志分析系统</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css" rel="stylesheet">
  <style>
    :root {
      --primary-color: #4361ee;
      --danger-color: #ef476f;
      --success-color: #06d6a0;
      --warning-color: #ffd166;
      --info-color: #118ab2;
      --gray-color: #6c757d;
      --light-bg: #f8f9fa;
      --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
      --sidebar-width: 250px;
    }
    
    body {
      background: #f4f6fa;
      font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
      overflow-x: hidden;
    }
    
    /* 侧边栏样式 */
    .sidebar {
      width: var(--sidebar-width);
      background: linear-gradient(180deg, #1a1f25 0%, #2c3038 100%);
      color: #fff;
      height: 100vh;
      position: fixed;
      left: 0;
      top: 0;
      bottom: 0;
      z-index: 100;
      box-shadow: 2px 0 10px rgba(0,0,0,0.1);
      transition: all 0.3s ease;
    }
    
    .sidebar-brand {
      padding: 1.5rem;
      font-weight: 600;
      color: #fff;
      font-size: 1.25rem;
      border-bottom: 1px solid rgba(255,255,255,0.1);
      margin-bottom: 1rem;
    }
    
    .sidebar .nav-link {
      color: rgba(255,255,255,0.75);
      padding: 0.8rem 1.5rem;
      margin-bottom: 0.25rem;
      border-radius: 6px;
      transition: all 0.2s;
    }
    
    .sidebar .nav-link:hover {
      color: #fff;
      background: rgba(255,255,255,0.1);
    }
    
    .sidebar .nav-link.active {
      background: var(--primary-color);
      color: #fff;
      box-shadow: 0 2px 8px rgba(67, 97, 238, 0.3);
    }
    
    .sidebar .nav-link i {
      width: 24px;
      text-align: center;
      margin-right: 8px;
    }
    
    /* 主内容区域 */
    .content {
      margin-left: var(--sidebar-width);
      padding: 1.5rem;
      min-height: 100vh;
      width: calc(100% - var(--sidebar-width));
    }
    
    .dashboard-main {
      max-width: 100%;
      margin: 0 auto;
    }
    
    .page-header {
      margin-bottom: 1.25rem;
      padding-bottom: 0.75rem;
      border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .page-title {
      font-weight: 700;
      color: #2d3748;
      font-size: 1.75rem;
      margin-bottom: 0;
    }
    
    /* 卡片样式统一 */
    .card {
      border: none;
      border-radius: 12px;
      box-shadow: var(--card-shadow);
      margin-bottom: 1.5rem;
      overflow: hidden;
    }
    
    .card-header {
      background: #fff;
      border-bottom: 1px solid rgba(0,0,0,0.05);
      font-weight: 600;
      font-size: 1.05rem;
      padding: 1rem 1.25rem;
      display: flex;
      align-items: center;
    }
    
    .card-header i {
      margin-right: 0.5rem;
      color: var(--primary-color);
    }
    
    .card-body {
      padding: 1.25rem;
    }
    
    /* 统计卡片 */
    .stat-card {
      height: 100%;
      padding: 1.25rem;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    
    .stat-title {
      font-size: 0.95rem;
      font-weight: 600;
      color: #64748b;
      margin-bottom: 0.75rem;
      display: flex;
      align-items: center;
    }
    
    .stat-title i {
      margin-right: 0.5rem;
      color: var(--primary-color);
      font-size: 1rem;
    }
    
    .stat-value {
      font-size: 1.75rem;
      font-weight: 700;
      color: var(--primary-color);
      line-height: 1.2;
    }
    
    .stat-value-danger { color: var(--danger-color); }
    .stat-value-success { color: var(--success-color); }
    .stat-value-info { color: var(--info-color); }
    .stat-value-gray { color: var(--gray-color); }
    
    .stat-detail {
      font-size: 0.9rem;
      color: var(--gray-color);
      margin-top: 0.5rem;
    }
    
    /* 图表卡片 */
    .chart-card {
      height: 100%;
    }
    
    .chart-container {
      position: relative;
      height: 250px;
      width: 100%;
    }
    
    /* 小图表 */
    .mini-chart {
      height: 180px;
    }
    
    /* 表格样式 */
    .table {
      margin-bottom: 0;
    }
    
    .table thead th {
      background: var(--light-bg);
      font-weight: 600;
      color: #475569;
      border-bottom: 2px solid #e9ecef;
      padding: 0.75rem 1rem;
      font-size: 0.9rem;
    }
    
    .table tbody td {
      padding: 0.75rem 1rem;
      vertical-align: middle;
      border-color: rgba(0,0,0,0.05);
      font-size: 0.9rem;
    }
    
    .table-hover tbody tr:hover {
      background: rgba(67, 97, 238, 0.05);
    }
    
    .badge {
      font-weight: 500;
      padding: 0.35em 0.65em;
      font-size: 0.75em;
    }
    
    /* 响应式调整 */
    @media (max-width: 992px) {
      .sidebar {
        width: 70px;
      }
      
      .sidebar .nav-link span,
      .sidebar-brand span {
        display: none;
      }
      
      .sidebar-brand {
        padding: 1.5rem 0;
        text-align: center;
      }
      
      .sidebar .nav-link {
        padding: 0.8rem 0;
        text-align: center;
      }
      
      .sidebar .nav-link i {
        margin-right: 0;
        font-size: 1.25rem;
      }
      
      .content {
        margin-left: 70px;
        width: calc(100% - 70px);
        padding: 1.25rem 1rem;
      }
    }
    
    @media (max-width: 768px) {
      .content {
        padding: 1rem 0.75rem;
      }
      
      .card-header {
        padding: 0.75rem 1rem;
      }
      
      .card-body {
        padding: 1rem;
      }
      
      .stat-value {
        font-size: 1.5rem;
      }
    }
  </style>
</head>
<body>
  <div class="d-flex">
    <!-- 侧边栏导航 -->
    <nav class="sidebar">
      <div class="sidebar-brand">
        <i class="fas fa-chart-line"></i>
        <span>日志分析系统</span>
      </div>
      <ul class="nav nav-pills flex-column">
        <li class="nav-item">
          <a href="dashboard.html" class="nav-link active">
            <i class="fas fa-tachometer-alt"></i>
            <span>仪表盘</span>
          </a>
        </li>
        <li class="nav-item">
          <a href="search.html" class="nav-link">
            <i class="fas fa-search"></i>
            <span>日志检索</span>
          </a>
        </li>
 
      </ul>
    </nav>
    
    <!-- 主内容区域 -->
    <main class="content">
      <div class="dashboard-main">
        <!-- 页面标题 -->
        <div class="page-header d-flex justify-content-between align-items-center">
          <h1 class="page-title">
            <i class="fas fa-tachometer-alt text-primary me-2"></i>
            日志分析仪表盘
          </h1>
          <div>
            <button class="btn btn-sm btn-outline-secondary">
              <i class="fas fa-sync-alt me-1"></i>刷新数据
            </button>
          </div>
        </div>
        
        <!-- 统计卡片行 -->
        <div class="row g-3 mb-4">
          <div class="col-sm-6 col-md-3">
            <div class="card h-100">
              <div class="stat-card">
                <div class="stat-title">
                  <i class="fas fa-file-alt"></i>今日总日志
                </div>
                <div class="stat-value">2,345</div>
                <div class="stat-detail">较昨日 <span class="text-success">+12%</span></div>
              </div>
            </div>
          </div>
          <div class="col-sm-6 col-md-3">
            <div class="card h-100">
              <div class="stat-card">
                <div class="stat-title">
                  <i class="fas fa-exclamation-triangle"></i>今日异常日志
                </div>
                <div class="stat-value stat-value-danger">123</div>
                <div class="stat-detail">占比 <span class="text-danger">5.2%</span></div>
              </div>
            </div>
          </div>
          <div class="col-sm-6 col-md-3">
            <div class="card h-100">
              <div class="stat-card">
                <div class="stat-title">
                  <i class="fas fa-layer-group"></i>日志类型分布
                </div>
                <div>
                  <div class="d-flex justify-content-between mb-1">
                    <span class="stat-value-gray">ACL</span>
                    <span class="fw-bold">1200</span>
                  </div>
                  <div class="d-flex justify-content-between mb-1">
                    <span class="stat-value-gray">IPS</span>
                    <span class="fw-bold">800</span>
                  </div>
                  <div class="d-flex justify-content-between">
                    <span class="stat-value-gray">RIS-LOG</span>
                    <span class="fw-bold">345</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-sm-6 col-md-3">
            <div class="card h-100">
              <div class="stat-card">
                <div class="stat-title">
                  <i class="fas fa-network-wired"></i>活跃源IP
                </div>
                <div class="stat-value stat-value-success">56</div>
                <div class="stat-detail">较昨日 <span class="text-success">+8</span></div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 图表行 -->
        <div class="row g-3 mb-4">
          <div class="col-md-6">
            <div class="card chart-card">
              <div class="card-header">
                <i class="fas fa-chart-pie"></i>今日日志等级分布
              </div>
              <div class="card-body">
                <div class="chart-container">
                  <canvas id="levelPie"></canvas>
                </div>
              </div>
            </div>
          </div>
          <div class="col-md-6">
            <div class="card chart-card">
              <div class="card-header">
                <i class="fas fa-chart-bar"></i>今日日志类型分布
              </div>
              <div class="card-body">
                <div class="chart-container">
                  <canvas id="typeBar"></canvas>
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 趋势图 -->
        <div class="row g-3 mb-4">
          <div class="col-12">
            <div class="card chart-card">
              <div class="card-header">
                <i class="fas fa-chart-line"></i>近7天日志趋势
              </div>
              <div class="card-body">
                <div class="chart-container">
                  <canvas id="logTrendChart"></canvas>
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 最新异常日志表格 - 单独一行 -->
        <div class="row g-3">
          <div class="col-12">
            <div class="card">
              <div class="card-header d-flex justify-content-between align-items-center">
                <div>
                  <i class="fas fa-bolt"></i>最新异常日志
                </div>
                <div>
                  <button class="btn btn-sm btn-outline-primary">
                    <i class="fas fa-filter me-1"></i>筛选
                  </button>
                </div>
              </div>
              <div class="card-body p-0">
                <div class="table-responsive">
                  <table class="table table-hover">
                    <thead>
                      <tr>
                        <th style="width: 10%">时间</th>
                        <th style="width: 8%">级别</th>
                        <th style="width: 10%">类型</th>
                        <th style="width: 12%">源IP</th>
                        <th style="width: 60%">关键信息</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                        <td>10:00:01</td>
                        <td><span class="badge bg-danger">ERROR</span></td>
                        <td>IPS</td>
                        <td>10.1.1.1</td>
                        <td>TCP_木马后门：检测到来自外部网络的可疑连接尝试，疑似远程控制木马活动，已阻断连接</td>
                      </tr>
                      <tr>
                        <td>09:58:12</td>
                        <td><span class="badge bg-warning">WARN</span></td>
                        <td>RIS-LOG</td>
                        <td>10.205.10.98</td>
                        <td>登录失败：用户admin在5分钟内连续3次登录失败，可能存在暴力破解尝试</td>
                      </tr>
                      <tr>
                        <td>09:55:33</td>
                        <td><span class="badge bg-danger">ERROR</span></td>
                        <td>ACL</td>
                        <td>172.16.232.6</td>
                        <td>拒绝访问：内部用户尝试访问未授权的敏感资源目录，违反安全策略规则ID:ACL-2345</td>
                      </tr>
                      <tr>
                        <td>09:48:21</td>
                        <td><span class="badge bg-warning">WARN</span></td>
                        <td>IPS</td>
                        <td>192.168.1.45</td>
                        <td>可疑扫描：检测到对内部网络多个端口的快速扫描行为，疑似网络探测活动</td>
                      </tr>
                      <tr>
                        <td>09:42:15</td>
                        <td><span class="badge bg-danger">ERROR</span></td>
                        <td>IPS</td>
                        <td>10.3.45.87</td>
                        <td>SQL注入攻击：检测到针对Web应用的SQL注入攻击尝试，已拦截并记录攻击特征</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                <div class="d-flex justify-content-between align-items-center px-3 py-2 border-top">
                  <div class="small text-muted">显示 5 条，共 123 条异常日志</div>
                  <div>
                    <a href="#" class="btn btn-sm btn-primary">查看全部 <i class="fas fa-chevron-right ms-1"></i></a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
  </div>

  <!-- 脚本 -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  <script>
    // 设置全局Chart.js选项
    Chart.defaults.font.family = "'Segoe UI', system-ui, -apple-system, sans-serif";
    Chart.defaults.font.size = 13;
    Chart.defaults.color = '#64748b';
    
    // 日志级别分布饼图
    new Chart(document.getElementById('levelPie'), {
      type: 'doughnut',
      data: {
        labels: ['INFO', 'WARN', 'ERROR'],
        datasets: [{
          data: [1800, 300, 245],
          backgroundColor: ['#4361ee', '#ffd166', '#ef476f'],
          borderWidth: 0,
          borderRadius: 4
        }]
      },
      options: {
        responsive: true,
        maintainAspectRatio: false,
        cutout: '65%',
        plugins: {
          legend: {
            position: 'bottom',
            labels: {
              padding: 20,
              usePointStyle: true,
              pointStyle: 'circle'
            }
          },
          tooltip: {
            backgroundColor: 'rgba(0,0,0,0.7)',
            padding: 10,
            titleFont: { weight: 'bold' },
            displayColors: false,
            callbacks: {
              label: function(context) {
                let value = context.raw;
                let total = context.dataset.data.reduce((a, b) => a + b, 0);
                let percentage = Math.round((value / total) * 100) + '%';
                return `${context.label}: ${value} (${percentage})`;
              }
            }
          }
        }
      }
    });
    
    // 日志类型分布柱状图
    new Chart(document.getElementById('typeBar'), {
      type: 'bar',
      data: {
        labels: ['ACL', 'RIS-LOG', 'IPS'],
        datasets: [{
          label: '日志数',
          data: [1200, 345, 800],
          backgroundColor: ['#4361ee', '#06d6a0', '#ef476f'],
          borderRadius: 8,
          maxBarThickness: 50
        }]
      },
      options: {
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
          legend: { display: false }
        },
        scales: {
          y: {
            beginAtZero: true,
            grid: {
              color: 'rgba(0,0,0,0.05)'
            }
          },
          x: {
            grid: {
              display: false
            }
          }
        }
      }
    });
    
    // 日志趋势线图
    new Chart(document.getElementById('logTrendChart'), {
      type: 'line',
      data: {
        labels: ['05-01','05-02','05-03','05-04','05-05','05-06','05-07'],
        datasets: [
          {
            label: '总日志',
            data: [300, 400, 350, 500, 420, 600, 550],
            borderColor: '#4361ee',
            backgroundColor: 'rgba(67, 97, 238, 0.1)',
            borderWidth: 2,
            fill: true,
            tension: 0.4,
            pointRadius: 4,
            pointBackgroundColor: '#fff',
            pointBorderColor: '#4361ee',
            pointBorderWidth: 2
          },
          {
            label: '异常日志',
            data: [30, 50, 40, 60, 45, 80, 70],
            borderColor: '#ef476f',
            backgroundColor: 'rgba(239, 71, 111, 0.1)',
            borderWidth: 2,
            fill: true,
            tension: 0.4,
            pointRadius: 4,
            pointBackgroundColor: '#fff',
            pointBorderColor: '#ef476f',
            pointBorderWidth: 2
          }
        ]
      },
      options: {
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
          legend: {
            position: 'bottom',
            labels: {
              usePointStyle: true,
              pointStyle: 'circle',
              padding: 20
            }
          },
          tooltip: {
            backgroundColor: 'rgba(0,0,0,0.7)',
            padding: 10,
            titleFont: { weight: 'bold' },
            intersect: false,
            mode: 'index'
          }
        },
        scales: {
          y: {
            beginAtZero: true,
            grid: {
              color: 'rgba(0,0,0,0.05)'
            }
          },
          x: {
            grid: {
              display: false
            }
          }
        }
      }
    });
  </script>
</body>
</html> 